<template>
	<view class="body d-s-c d-c">
		<image src="@/static/head.png" mode="widthFix" class="ww100"></image>
		<view class="p60">
			<view class="tip sub f22 mb40">*如您是欧比内部销售人员，点击下方按钮进行注册，我们将对您的手机号进行校验，非欧比内部销售人员，不允许注册。</view>
			<view class="item mb20 d-b-c pl40 pr40">
				<input  class="f28" type="number" placeholder="输入手机号" />
			</view>
			<view class="item d-b-c pl40 pr40">
				<input class="f28 flex-1" type="number" placeholder="输入验证码" />
				<view class="f28" :class="data.time==0?'code':'deCode'">{{data.time==0?'发送验证码':`重新发送（${data.time}）`}}</view>
			</view>
			<view class="mb40 mt50">
				<label class="radio f24" @click="setRadio">
					<radio :checked="data.radio" color="#d2000f" /> 我已阅读<text>《用户协议》</text>与<text>《隐私政策》</text>，并同意协议内容
				</label>
			</view>
			<view class="ww100">
				<up-button throttleTime="1000" @click="login" shape='circle' color='#d2000f' text="注册"></up-button>
			</view>
		</view>
	</view>
</template>
<script setup>
	import {
		reactive
	} from 'vue'
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		useStore
	} from "vuex"
	import {
		test
	} from '@/uni_modules/uview-plus';
	const store = useStore()
	const data = reactive({
		radio: false,
		tel: '',
		code: "",
		time: 0,
		timer: null
	})
	async function getCode() {
		if (data.time != 0) return
		if (!test.mobile(data.tel)) return store.commit('tip', '请输入正确手机号')
		const res = await store.dispatch('request', {
			url: store.state.api.sendSmsCode,
			data: {
				phoneNumber: data.tel
			}
		})
		if (res.code == 1) {
			store.commit('tip', '发送成功')
			data.time = 59
			clearInterval(data.timer)
			data.timer = setInterval(() => {
				data.time = data.time - 1
			}, 1000)
		} else {
			store.commit('tip', '发送失败')
		}
	}
	async function login() {
		uni.switchTab({
			url: '/pages/index/index'
		})
		return
		if (!data.radio) return store.commit('tip', '请阅读《用户协议》与《隐私政策》，并同意协议内容')
		// store.commit('jump','/pages/index/index')
		if (!test.mobile(data.tel)) return store.commit('tip', '请输正确入手机号')
		if (!test.mobile(data.tel)) return store.commit('tip', '请输验证码')
		const res = await store.dispatch('request', {
			url: store.state.api.checkSmsCode,
			data: {
				phoneNumber: data.tel,
				code: data.code
			},
		})
		if (res.code == 1) {
			store.commit('tip', '登录成功')
			// console.log(res);
			uni.setStorageSync('token', res.data.userinfo.token)
			uni.setStorageSync('userinfo', res.data.userinfo)
			setTimeout(() => {
				store.commit('jump', '/pages/index/index')
			}, 1000)
		} else {
			store.commit('tip', '登录失败')
		}
	}

	function setRadio() {
		data.radio = !data.radio
	}
	onLoad(() => {
		if (uni.getStorageSync('token')) {
			uni.reLaunch({
				url: '/pages/index/index'
			})
		}
	})
</script>
<style scoped lang="scss">
	.item{
		background-color: #fff;
		border-radius: 60rpx;
		height: 70rpx;		
		box-shadow: 0rpx 5rpx 15rpx 0rpx rgba(210, 0, 15, .2);
	}
	.code{
		color: #d2000f;
	}
	.deCode{
		color: #999;
	}
	.body {
		background-color: #fbf7eb;

		.logo {
			width: 250rpx;
		}
	}

	.radio {
		color: #999;

		radio {
			transform: scale(0.8);
		}

		text {
			color: $uni-color-error
		}
	}
</style>